package 
{
	import feathers.controls.Button;
	import feathers.controls.Label;
	import feathers.controls.Screen;
	import Media.ExtendedMetalWorksMobileTheme;
	import Screens.NavigationEvent;
	import starling.events.Event
	import starling.display.Sprite;
	
	/**
	 * @author Simon Claeye
	 * @version 2.0
	 */
	public class MainMenu extends Screen
	{
		protected var theme:ExtendedMetalWorksMobileTheme;
		
		public function MainMenu():void 
		{
			this.addEventListener( Event.ADDED_TO_STAGE, addedToStageHandler );
		}
		
		private function addedToStageHandler(event:Event):void
		{
			this.theme = new ExtendedMetalWorksMobileTheme(this.stage);			
			this.backButtonHandler = backHandler;	// handles the back hardware key on android
			
			//Images Button
			var imagesButton:Button = new Button();
			imagesButton.label = "Take Images";
			imagesButton.nameList.add(ExtendedMetalWorksMobileTheme.MENU_BUTTON);
			
			imagesButton.x = (this.stage.stageWidth / 8);
			imagesButton.y = (this.stage.stageHeight / 8) - 20 + (this.stage.stageHeight / 8);
			imagesButton.setSize(((this.stage.stageWidth / 4) * 3), this.stage.stageHeight / 8);
			
			imagesButton.addEventListener(Event.TRIGGERED, takeImages);
			addChild(imagesButton);
			
			//Upload Button
			var uploadButton:Button = new Button();
			uploadButton.nameList.add(ExtendedMetalWorksMobileTheme.MENU_BUTTON);			
			uploadButton.label = "My Images";
			
			uploadButton.x = (this.stage.stageWidth / 8);
			uploadButton.y = (this.stage.stageHeight / 8) + 2*(this.stage.stageHeight / 8);
			uploadButton.setSize(((this.stage.stageWidth / 4) * 3), this.stage.stageHeight / 8);
			
			uploadButton.addEventListener(Event.TRIGGERED, uploadImages);
			addChild(uploadButton);
			
			//Close Button
			var closeButton:Button = new Button();
			closeButton.nameList.add(ExtendedMetalWorksMobileTheme.MENU_BUTTON);
			closeButton.label = "Close";
 
			closeButton.x = (this.stage.stageWidth / 8);
			closeButton.y = (this.stage.stageHeight / 8) + 20 + 4*(this.stage.stageHeight / 8);
			closeButton.setSize(((this.stage.stageWidth / 4) * 3), this.stage.stageHeight / 8);
			
			closeButton.addEventListener(Event.TRIGGERED, close);
			addChild(closeButton);
		}
		
		/**
		 * A function to dispatch an event when the back hardware key
		 * is pressed on android.
		 */
		private function backHandler():void
		{
			dispatchEvent(new NavigationEvent(NavigationEvent.CLOSE));
		}
		
		private function takeImages(event:Event):void
		{
			dispatchEvent( new NavigationEvent(NavigationEvent.TAKE_IMAGES));
		}
		
		private function uploadImages(event:Event):void
		{
			dispatchEvent( new NavigationEvent(NavigationEvent.UPLOAD));
		}
		
		private function close(event:Event):void
		{
			dispatchEvent(new NavigationEvent(NavigationEvent.CLOSE));
		}
	}
	
}